package com.atldy.commerce.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Objects;
import java.util.stream.Stream;

/**
 * @version 1.0
 * @Author: lidongyang
 * @CreateTime: 2021-08-17 12:37
 * @Description： 商品品牌
 */
@Getter
@AllArgsConstructor
public enum BrandCategory {

    BRAND_A("10001", "商品 A"),
    BRAND_B("10002", "商品 A"),
    BRAND_C("10003", "商品 A"),
    BRAND_D("10004", "商品 D"),
    BRAND_E("10005", "商品 E");


    /**
     * 状态码
     */
    @EnumValue
    @JsonValue    //标记响应json值
    private final String code;

    /**
     * 状态描述
     */
    private final String description;


    /**
     * 根据code获取商品
     */
    public static BrandCategory of(String code) {
        Objects.requireNonNull(code);
        return Stream.of(values())
                .filter(brandCategory -> brandCategory.getCode().equals(code))
                .findAny()
                .orElseThrow(() -> new IllegalArgumentException(code + "not exists"));
    }


    @Override
    public String toString() {
        return this.description;
    }
}